package rdd.operate;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;

import java.util.Arrays;
import java.util.List;

public class Spark66_Operate_CountFirstTake {
    public static void main(String[] args) {
        final SparkConf conf = new SparkConf();
        conf.setMaster("local");
        conf.setAppName("spark");
        final JavaSparkContext jsc = new JavaSparkContext(conf);

        final List<Integer>  nums = Arrays.asList(4,3,2,1);
        final JavaRDD<Integer> rdd = jsc.parallelize(nums,2);

        //Count方法，用于统计rdd中一共有多少个元素
        long count = rdd.count();
        System.out.println(count);

        //first用于获取第一个元素
        Integer first = rdd.first();
        System.out.println(first);

        //take用于获取前面X个元素
        List<Integer> take = rdd.take(2);
        System.out.println(take);

        jsc.close();
    }
}
